﻿#include "IntelligentCreatureDialogs.h"
#include "../../MirGraphics/MLibrary.h"
#include "../../MirSounds/SoundManager.h"
#include "../GameScene.h"
#include "../../../Shared/Functions/Functions.h"
#include "../../MirControls/MirInputBox.h"
#include "../../../Shared/ClientPackets.h"
#include "../../MirNetwork/Network.h"
#include "../../../Shared/Language.h"
#include "../../Forms/Client.CMain.h"
#include "../../MirControls/MirMessageBox.h"

using namespace Client::MirControls;
using namespace Client::MirGraphics;
using namespace Client::MirNetwork;
using namespace Client::MirSounds;
namespace C = ClientPackets;

namespace Client::MirScenes::Dialogs
{

    IntelligentCreatureDialog::IntelligentCreatureDialog()
    {
        setIndex(468);
        setLibrary(Libraries::Title);
        setMovable(true);
        setSort(true);
        setLocation(getCenter());
        BeforeDraw += IntelligentCreatureDialog_BeforeDraw;

        #pragma region CreatureButtons
        CloseButton = new MirButton();
        CloseButton->setHoverIndex(361);
        CloseButton->setIndex(360);
        Point tempVar(getSize()->Width - 25, 3);
        CloseButton->setLocation(&tempVar);
        CloseButton->setLibrary(Libraries::Prguse2);
        CloseButton->setParent(this);
        CloseButton->setPressedIndex(362);
        CloseButton->setSound(SoundList::ButtonA);
        CloseButton->Click += [&] (o, e)
        {
            Hide();
        };

        HelpPetButton = new MirButton();
        HelpPetButton->setHoverIndex(258);
        HelpPetButton->setIndex(257);
        Point tempVar2(getSize()->Width - 48, 3);
        HelpPetButton->setLocation(&tempVar2);
        HelpPetButton->setLibrary(Libraries::Prguse2);
        HelpPetButton->setParent(this);
        HelpPetButton->setPressedIndex(259);
        HelpPetButton->setSound(SoundList::ButtonA);

        CreatureRenameButton = new MirButton();
        CreatureRenameButton->setHoverIndex(571);
        CreatureRenameButton->setIndex(570);
        Point tempVar3(344, 50);
        CreatureRenameButton->setLocation(&tempVar3);
        CreatureRenameButton->setLibrary(Libraries::Title);
        CreatureRenameButton->setParent(this);
        CreatureRenameButton->setPressedIndex(572);
        CreatureRenameButton->setSound(SoundList::ButtonA);
        CreatureRenameButton->setVisible(false);
        CreatureRenameButton->Click += ButtonClick;

        SummonButton = new MirButton();
        SummonButton->setIndex(576);
        SummonButton->setHoverIndex(577);
        SummonButton->setPressedIndex(578);
        Point tempVar4(113, 217);
        SummonButton->setLocation(&tempVar4);
        SummonButton->setLibrary(Libraries::Title);
        SummonButton->setParent(this);
        SummonButton->setSound(SoundList::ButtonA);
        SummonButton->Click += ButtonClick;

        DismissButton = new MirButton();
        DismissButton->setHoverIndex(581);
        DismissButton->setIndex(580);
        Point tempVar5(113, 217);
        DismissButton->setLocation(&tempVar5);
        DismissButton->setLibrary(Libraries::Title);
        DismissButton->setParent(this);
        DismissButton->setPressedIndex(582);
        DismissButton->setSound(SoundList::ButtonA);
        DismissButton->Click += ButtonClick;

        ReleaseButton = new MirButton();
        ReleaseButton->setHoverIndex(584);
        ReleaseButton->setIndex(583);
        Point tempVar6(255, 217);
        ReleaseButton->setLocation(&tempVar6);
        ReleaseButton->setLibrary(Libraries::Title);
        ReleaseButton->setParent(this);
        ReleaseButton->setPressedIndex(585);
        ReleaseButton->setSound(SoundList::ButtonA);
        ReleaseButton->Click += ButtonClick;

        OptionsMenuButton = new MirButton();
        OptionsMenuButton->setHoverIndex(574);
        OptionsMenuButton->setIndex(573);
        Point tempVar7(375, 160);
        OptionsMenuButton->setLocation(&tempVar7);
        OptionsMenuButton->setLibrary(Libraries::Title);
        OptionsMenuButton->setParent(this);
        OptionsMenuButton->setPressedIndex(575);
        OptionsMenuButton->setSound(SoundList::ButtonA);
        OptionsMenuButton->Click += ButtonClick;

        AutomaticModeButton = new MirButton();
        AutomaticModeButton->setHoverIndex(611);
        AutomaticModeButton->setIndex(610);
        Point tempVar8(375, 187);
        AutomaticModeButton->setLocation(&tempVar8);
        AutomaticModeButton->setLibrary(Libraries::Title);
        AutomaticModeButton->setParent(this);
        AutomaticModeButton->setPressedIndex(612);
        AutomaticModeButton->setSound(SoundList::ButtonA);
        AutomaticModeButton->Click += ButtonClick;

        SemiAutoModeButton = new MirButton();
        SemiAutoModeButton->setHoverIndex(614);
        SemiAutoModeButton->setIndex(613);
        Point tempVar9(375, 187);
        SemiAutoModeButton->setLocation(&tempVar9);
        SemiAutoModeButton->setLibrary(Libraries::Title);
        SemiAutoModeButton->setParent(this);
        SemiAutoModeButton->setPressedIndex(615);
        SemiAutoModeButton->setSound(SoundList::ButtonA);
        SemiAutoModeButton->Click += ButtonClick;

        CreatureButtons = std::vector<CreatureButton*>(10);
        for (int i = 0; i < CreatureButtons.size(); i++)
        {
            int offsetX = i * 81;
            int offsetY = 259;
            if (i >= 5)
            {
                offsetX = (i - 5) * 81;
                offsetY += 40;
            }
            CreatureButton *tempVar10 = new CreatureButton();
            tempVar10->idx = i;
            tempVar10->setParent(this);
            tempVar10->setVisible(false);
            Point tempVar11((44 + offsetX), offsetY);
            tempVar10->setLocation(&tempVar11);
            CreatureButtons[i] = tempVar10;

            delete tempVar10;
        }
        #pragma endregion

        #pragma region CreatureImage
        CreatureImage = new MirAnimatedControl();
        CreatureImage->setAnimated(false);
        CreatureImage->setAnimationCount(4);
        CreatureImage->setAnimationDelay(250);
        CreatureImage->setIndex(0);
        CreatureImage->setLibrary(Libraries::Prguse2);
        CreatureImage->setLoop(true);
        CreatureImage->setParent(this);
        CreatureImage->setNotControl(true);
        CreatureImage->setUseOffSet(true);
        Point tempVar12(50, 110);
        CreatureImage->setLocation(&tempVar12);

        FullnessBG = new MirImageControl();
        FullnessBG->setIndex(530);
        FullnessBG->setLibrary(Libraries::Prguse2);
        Point tempVar13(185, 129);
        FullnessBG->setLocation(&tempVar13);
        FullnessBG->setParent(this);
        FullnessBG->setNotControl(true);
        FullnessBG->MouseEnter += Control_MouseEnter;
        FullnessBG->MouseLeave += Control_MouseLeave;

        FullnessFG = new MirImageControl();
        FullnessFG->setIndex(531);
        FullnessFG->setLibrary(Libraries::Prguse2);
        Point tempVar14(185, 129);
        FullnessFG->setLocation(&tempVar14);
        FullnessFG->setParent(this);
        FullnessFG->setDrawImage(false);
        FullnessFG->AfterDraw += FullnessForeGround_AfterDraw;
        FullnessFG->MouseEnter += Control_MouseEnter;
        FullnessFG->MouseLeave += Control_MouseLeave;

        FullnessMin = new MirImageControl();
        FullnessMin->setIndex(532);
        FullnessMin->setLibrary(Libraries::Prguse2);
        Point tempVar15(179, 118);
        FullnessMin->setLocation(&tempVar15);
        FullnessMin->setParent(this);
        FullnessMin->MouseEnter += Control_MouseEnter;
        FullnessMin->MouseLeave += Control_MouseLeave;

        FullnessNow = new MirImageControl();
        FullnessNow->setIndex(533);
        FullnessNow->setLibrary(Libraries::Prguse2);
        Point tempVar16(179, 143);
        FullnessNow->setLocation(&tempVar16);
        FullnessNow->setParent(this);
        FullnessNow->setNotControl(true);

        PearlImage = new MirImageControl();
        PearlImage->setIndex(427);
        PearlImage->setLibrary(Libraries::Prguse2);
        Point tempVar17(29, 348);
        PearlImage->setLocation(&tempVar17);
        PearlImage->setParent(this);
        PearlImage->setNotControl(true);

        BlackStoneImageBG = new MirImageControl();
        BlackStoneImageBG->setIndex(428);
        BlackStoneImageBG->setLibrary(Libraries::Prguse2);
        Point tempVar18(215, 348);
        BlackStoneImageBG->setLocation(&tempVar18);
        BlackStoneImageBG->setParent(this);
        BlackStoneImageBG->setVisible(true);
        BlackStoneImageBG->setNotControl(true);
        BlackStoneImageBG->MouseEnter += Control_MouseEnter;
        BlackStoneImageBG->MouseLeave += Control_MouseLeave;

        BlackStoneImageFG = new MirImageControl();
        BlackStoneImageFG->setIndex(420);
        BlackStoneImageFG->setLibrary(Libraries::Prguse2);
        Point tempVar19(242, 353);
        BlackStoneImageFG->setLocation(&tempVar19);
        BlackStoneImageFG->setParent(this);
        BlackStoneImageFG->setVisible(true);
        BlackStoneImageFG->setDrawImage(false);
        BlackStoneImageFG->AfterDraw += BlackStoneImageFG_AfterDraw;
        BlackStoneImageFG->MouseEnter += Control_MouseEnter;
        BlackStoneImageFG->MouseLeave += Control_MouseLeave;

        #pragma endregion

        #pragma region CreatureLabels
        CreatureName = new MirLabel();
        CreatureName->setParent(this);
        Point tempVar20(170, 50);
        CreatureName->setLocation(&tempVar20);
        CreatureName->setDrawFormat(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter);
        Size tempVar21(166, 21);
        CreatureName->setSize(&tempVar21);
        CreatureName->setNotControl(true);

        CreatureDeadline = new MirLabel();
        CreatureDeadline->setParent(this);
        Point tempVar22(140, 85);
        CreatureDeadline->setLocation(&tempVar22);
        CreatureDeadline->setDrawFormat(TextFormatFlags::VerticalCenter);
        Size tempVar23(350, 21);
        CreatureDeadline->setSize(&tempVar23);
        CreatureDeadline->setNotControl(true);

        CreaturePearls = new MirLabel();
        CreaturePearls->setAutoSize(true);
        CreaturePearls->setParent(this);
        Point tempVar24(53, 348);
        CreaturePearls->setLocation(&tempVar24);
        CreaturePearls->setDrawFormat(TextFormatFlags::VerticalCenter);
        CreaturePearls->setText("0");
        CreaturePearls->setNotControl(true);

        CreatureInfo = new MirLabel();
        CreatureInfo->setParent(this);
        Point tempVar25(19, 161);
        CreatureInfo->setLocation(&tempVar25);
        CreatureInfo->setDrawFormat(TextFormatFlags::VerticalCenter);
        Size tempVar26(350, 15);
        CreatureInfo->setSize(&tempVar26);
        CreatureInfo->setNotControl(true);

        CreatureInfo1 = new MirLabel();
        CreatureInfo1->setParent(this);
        Point tempVar27(19, 176);
        CreatureInfo1->setLocation(&tempVar27);
        CreatureInfo1->setDrawFormat(TextFormatFlags::VerticalCenter);
        Size tempVar28(350, 15);
        CreatureInfo1->setSize(&tempVar28);
        CreatureInfo1->setNotControl(true);

        CreatureInfo2 = new MirLabel();
        CreatureInfo2->setParent(this);
        Point tempVar29(19, 191);
        CreatureInfo2->setLocation(&tempVar29);
        CreatureInfo2->setDrawFormat(TextFormatFlags::VerticalCenter);
        Size tempVar30(350, 15);
        CreatureInfo2->setSize(&tempVar30);
        CreatureInfo2->setNotControl(true);

        CreatureMaintainFoodBuff = new MirLabel();
        CreatureMaintainFoodBuff->setParent(this);
        Point tempVar31(25, 25);
        CreatureMaintainFoodBuff->setLocation(&tempVar31);
        CreatureMaintainFoodBuff->setDrawFormat(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter);
        Size tempVar32(166, 21);
        CreatureMaintainFoodBuff->setSize(&tempVar32);
        CreatureMaintainFoodBuff->setNotControl(true);
        CreatureMaintainFoodBuff->setVisible(false);

        HoverLabel = new MirLabel();
        HoverLabel->setParent(this);
        Point tempVar33(0, 0);
        HoverLabel->setLocation(&tempVar33);
        HoverLabel->setDrawFormat(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter);
        Size tempVar34(100, 15);
        HoverLabel->setSize(&tempVar34);
        HoverLabel->setNotControl(true);
        #pragma endregion

    }

    void IntelligentCreatureDialog::IntelligentCreatureDialog_BeforeDraw(std::any sender, EventArgs *e)
    {
        RefreshDialog();
    }

    void IntelligentCreatureDialog::FullnessForeGround_AfterDraw(std::any sender, EventArgs *e)
    {
        int selectedCreature = BeforeAfterDraw();
        if (selectedCreature < 0)
        {
            return;
        }

        double percent = GameScene::getUser()->IntelligentCreatures[selectedCreature]->Fullness / (static_cast<double>(10000));
        if (percent > 1)
        {
            percent = 1;
        }
        if (percent <= 0)
        {
            Point tempVar(179, 143);
            FullnessNow->setLocation(&tempVar);
            return;
        }

        if (HoverLabel->getVisible() && HoverLabelParent != nullptr && HoverLabelParent == FullnessFG)
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
            HoverLabel->setText(GameScene::getUser()->IntelligentCreatures[selectedCreature]->Fullness.ToString() + " / 10000");
        }

        Rectangle *section = new Rectangle();
        section->Size = new Size(static_cast<int>((FullnessFG->getSize()->Width) * percent), FullnessFG->getSize()->Height);

        FullnessFG->getLibrary()->Draw(FullnessFG->getIndex(), section, FullnessFG->getDisplayLocation(), Color::White, false);


        Point tempVar2(FullnessFG->getLocation()->X + section->Size->Width - 8, FullnessNow->getLocation()->Y);
        FullnessNow->setLocation(&tempVar2);

        percent = GameScene::getUser()->IntelligentCreatures[selectedCreature]->CreatureRules.MinimalFullness / (static_cast<double>(10000));
        Size *size = new Size(static_cast<int>((FullnessFG->getSize()->Width) * percent), FullnessFG->getSize()->Height);

        Point tempVar3(FullnessFG->getLocation()->X + size->Width - 8, FullnessMin->getLocation()->Y);
        FullnessMin->setLocation(&tempVar3);

        delete size;
//C# TO C++ CONVERTER TODO TASK: A 'delete section' statement was not added since section was passed to a method or constructor. Handle memory management manually.
    }

    void IntelligentCreatureDialog::BlackStoneImageFG_AfterDraw(std::any sender, EventArgs *e)
    {
        int selectedCreature = BeforeAfterDraw();
        if (selectedCreature < 0)
        {
            return;
        }

        double percent = GameScene::getUser()->IntelligentCreatures[selectedCreature]->BlackstoneTime / (static_cast<double>(blackstoneProduceTime));
        if (percent > 1)
        {
            percent = 1;
        }
        if (percent <= 0)
        {
            return;
        }

        if (HoverLabel->getVisible() && HoverLabelParent != nullptr && HoverLabelParent == BlackStoneImageFG)
        {
            if (GameScene::getUser()->IntelligentCreatures[selectedCreature]->CreatureRules.CanProduceBlackStone)
            {
                HoverLabel->setText(StringHelper::formatSimple("{0}", Functions::PrintTimeSpanFromSeconds(blackstoneProduceTime - GameScene::getUser()->IntelligentCreatures[selectedCreature]->BlackstoneTime)));
            }
            else
            {
                HoverLabel->setText("No Production.");
            }
        }

        Rectangle *section = new Rectangle();
        section->Size = new Size(static_cast<int>((BlackStoneImageFG->getSize()->Width) * percent), BlackStoneImageFG->getSize()->Height);

        BlackStoneImageFG->getLibrary()->Draw(BlackStoneImageFG->getIndex(), section, BlackStoneImageFG->getDisplayLocation(), Color::White, false);

//C# TO C++ CONVERTER TODO TASK: A 'delete section' statement was not added since section was passed to a method or constructor. Handle memory management manually.
    }

    void IntelligentCreatureDialog::Control_MouseEnter(std::any sender, EventArgs *e)
    {
        int selectedCreature = BeforeAfterDraw();
        if (selectedCreature < 0)
        {
            return;
        }

        if (obj::type() == typeid(Client::MirControls::MirImageControl) && std::any_cast<Client::MirControls::MirImageControl>(obj) == FullnessMin)
        {
            HoverLabel->setVisible(true);
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
            HoverLabel->setText("Needed " + GameScene::getUser()->IntelligentCreatures[selectedCreature]->CreatureRules.MinimalFullness.ToString());
            Size tempVar(150, 15);
            HoverLabel->setSize(&tempVar);
            Point tempVar2((FullnessMin->getLocation()->X + 8) - (HoverLabel->getSize()->Width / 2), FullnessFG->getLocation()->Y - 18);
            HoverLabel->setLocation(&tempVar2);
        }
        if (obj::type() == typeid(Client::MirControls::MirImageControl) && std::any_cast<Client::MirControls::MirImageControl>(obj) == FullnessFG || obj::type() == typeid(Client::MirControls::MirImageControl) && std::any_cast<Client::MirControls::MirImageControl>(obj) == FullnessBG)
        {
            HoverLabel->setVisible(true);
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
            HoverLabel->setText(GameScene::getUser()->IntelligentCreatures[selectedCreature]->Fullness.ToString() + " / 10000");
            HoverLabel->setSize(FullnessFG->getSize());
            Point tempVar3(FullnessFG->getLocation()->X, FullnessFG->getLocation()->Y - 2);
            HoverLabel->setLocation(&tempVar3);
            HoverLabelParent = FullnessFG;
        }
        if (obj::type() == typeid(Client::MirControls::MirImageControl) && std::any_cast<Client::MirControls::MirImageControl>(obj) == BlackStoneImageBG || obj::type() == typeid(Client::MirControls::MirImageControl) && std::any_cast<Client::MirControls::MirImageControl>(obj) == BlackStoneImageFG)
        {
            HoverLabel->setVisible(true);
            HoverLabel->setText(StringHelper::formatSimple("{0}", Functions::PrintTimeSpanFromSeconds(blackstoneProduceTime - GameScene::getUser()->IntelligentCreatures[selectedCreature]->BlackstoneTime)));
            HoverLabel->setSize(BlackStoneImageBG->getSize());
            Point tempVar4(BlackStoneImageBG->getLocation()->X + 5, BlackStoneImageBG->getLocation()->Y - 2);
            HoverLabel->setLocation(&tempVar4);
            HoverLabelParent = BlackStoneImageFG;
        }
    }

    void IntelligentCreatureDialog::Control_MouseLeave(std::any sender, EventArgs *e)
    {
        HoverLabel->setText("");
        HoverLabel->setVisible(false);
        HoverLabel->setParent(this);
        HoverLabelParent = nullptr;
    }

    void IntelligentCreatureDialog::ButtonClick(std::any sender, EventArgs *e)
    {
        int selectedCreature = BeforeAfterDraw();
        if (selectedCreature < 0)
        {
            return;
        }

        bool needSummon = false, needDismiss = false, needRelease = false, needUpdate = false;

        if (obj::type() == typeid(Client::MirControls::MirButton) && std::any_cast<Client::MirControls::MirButton>(obj) == CreatureRenameButton)
        {
            MirInputBox *inputBox = new MirInputBox("Please enter a new name for the creature.");
            inputBox->InputTextBox->setText(GameScene::getUser()->IntelligentCreatures[selectedCreature]->CustomName);
            inputBox->OKButton->Click += [&] (o1, e1)
            {
                Update(); //refresh changes
                GameScene::getUser()->IntelligentCreatures[selectedCreature]->CustomName = inputBox->InputTextBox->getText();
                C::UpdateIntelligentCreature *tempVar = new C::UpdateIntelligentCreature();
                tempVar->Creature = GameScene::getUser()->IntelligentCreatures[selectedCreature];
                Network::Enqueue(tempVar);
                inputBox->Dispose();

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
            };
            inputBox->Show();
            CreatureRenameButton->setVisible(false);

            delete inputBox;
            return;
        }
        if (obj::type() == typeid(Client::MirControls::MirButton) && std::any_cast<Client::MirControls::MirButton>(obj) == SummonButton)
        {
            //if (GameScene.User.IntelligentCreatures[selectedCreature].Fullness == 0)
            //{
            //    GameScene.Scene.ChatDialog.ReceiveChat((string.Format("Creature {0} is starving, revitalize first.", GameScene.User.IntelligentCreatures[selectedCreature].CustomName)), ChatType.System);
            //}

            needSummon = true;
            needUpdate = true;

            SummonButton->setEnabled(false);
            DismissButton->setEnabled(true);
            DismissButton->setVisible(true);
        }
        if (obj::type() == typeid(Client::MirControls::MirButton) && std::any_cast<Client::MirControls::MirButton>(obj) == DismissButton)
        {
            needDismiss = true;
            needUpdate = true;

            SummonButton->setEnabled(true);
            DismissButton->setEnabled(false);
            DismissButton->setVisible(false);
        }
        if (obj::type() == typeid(Client::MirControls::MirButton) && std::any_cast<Client::MirControls::MirButton>(obj) == ReleaseButton)
        {
            MirInputBox *verificationBox = new MirInputBox("Please enter the creature's name for verification.");
            verificationBox->OKButton->Click += [&] (o1, e1)
            {
                if (std::string::Compare(verificationBox->InputTextBox->getText(), GameScene::getUser()->IntelligentCreatures[selectedCreature]->CustomName, StringComparison::OrdinalIgnoreCase) != 0)
                {
                    GameScene::Scene->ChatDialog->ReceiveChat("Verification Failed!!", ChatType::System);
                }
                else
                {
                    //clear all and get new info after server got update
                    for (int i = 0; i < CreatureButtons.size(); i++)
                    {
                        CreatureButtons[i]->Clear();
                    }
                    Hide();
                    C::UpdateIntelligentCreature *tempVar2 = new C::UpdateIntelligentCreature();
                    tempVar2->Creature = GameScene::getUser()->IntelligentCreatures[selectedCreature];
                    tempVar2->ReleaseMe = true;
                    Network::Enqueue(tempVar2);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar2' statement was not added since tempVar2 was passed to a method or constructor. Handle memory management manually.
                }
                verificationBox->Dispose();
            };
            verificationBox->Show();

            delete verificationBox;
            return;
        }
        if (obj::type() == typeid(Client::MirControls::MirButton) && std::any_cast<Client::MirControls::MirButton>(obj) == SemiAutoModeButton)
        {
            //make sure rules allow Automatic Mode
            if (!GameScene::getUser()->IntelligentCreatures[selectedCreature]->CreatureRules.AutoPickupEnabled)
            {
                return;
            }

            //turn on automatic pickupmode
            SemiAutoModeButton->setVisible(false);
            AutomaticModeButton->setVisible(true);
            GameScene::getUser()->IntelligentCreatures[selectedCreature]->petMode = IntelligentCreaturePickupMode::Automatic;
            needUpdate = true;
        }
        if (obj::type() == typeid(Client::MirControls::MirButton) && std::any_cast<Client::MirControls::MirButton>(obj) == AutomaticModeButton)
        {
            //make sure rules allow SemiAutomatic Mode
            if (!GameScene::getUser()->IntelligentCreatures[selectedCreature]->CreatureRules.SemiAutoPickupEnabled)
            {
                return;
            }

            //turn on semiauto pickupmode
            AutomaticModeButton->setVisible(false);
            SemiAutoModeButton->setVisible(true);
            GameScene::getUser()->IntelligentCreatures[selectedCreature]->petMode = IntelligentCreaturePickupMode::SemiAutomatic;
            needUpdate = true;
        }
        if (obj::type() == typeid(Client::MirControls::MirButton) && std::any_cast<Client::MirControls::MirButton>(obj) == OptionsMenuButton)
        {
            //show ItemFilter
            if (!GameScene::Scene->IntelligentCreatureOptionsDialog->getVisible())
            {
                GameScene::Scene->IntelligentCreatureOptionsDialog->Show(GameScene::getUser()->IntelligentCreatures[selectedCreature]->Filter);
            }
            if (!GameScene::Scene->IntelligentCreatureOptionsGradeDialog->getVisible())
            {
                GameScene::Scene->IntelligentCreatureOptionsGradeDialog->Show(GameScene::getUser()->IntelligentCreatures[selectedCreature]->Filter->PickupGrade);
            }
        }

        if (needUpdate)
        {
            Update(); //refresh changes
            C::UpdateIntelligentCreature *tempVar3 = new C::UpdateIntelligentCreature();
            tempVar3->Creature = GameScene::getUser()->IntelligentCreatures[selectedCreature];
            tempVar3->SummonMe = needSummon;
            tempVar3->UnSummonMe = needDismiss;
            tempVar3->ReleaseMe = needRelease;
            Network::Enqueue(tempVar3);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar3' statement was not added since tempVar3 was passed to a method or constructor. Handle memory management manually.
        }
    }

    void IntelligentCreatureDialog::Update()
    {
        if (!getVisible())
        {
            return;
        }
        RefreshDialog();
    }

    void IntelligentCreatureDialog::RefreshDialog()
    {
        RefreshInfo();
        RefreshUI();
        RefreshMode();
        BeforeAfterDraw();
        DrawCreatureAnimation();
    }

    void IntelligentCreatureDialog::RefreshInfo()
    {
        CreaturePearls->setText(std::to_string(GameScene::getUser()->PearlCount));

        int SelectedButton = -1;

        for (int i = 0; i < CreatureButtons.size(); i++)
        {
            if (i >= GameScene::getUser()->IntelligentCreatures.size())
            {
                CreatureButtons[i]->Clear();
                continue;
            }

            CreatureButtons[i]->setVisible(true);
            CreatureButtons[i]->Update(GameScene::getUser()->IntelligentCreatures[i], showing);

            //Check what creature is currently summoned if at all
            if (showing && GameScene::getUser()->CreatureSummoned && CreatureButtons[i]->PetType == GameScene::getUser()->SummonedCreatureType)
            {
                SelectedButton = i;
            }
        }
        showing = false;

        if (SelectedButton < 0)
        {
            return;
        }
        CreatureButtons[SelectedButton]->SelectButton();
    }

    void IntelligentCreatureDialog::RefreshUI()
    {
        bool error = false;
        int selectedCreature = -1;
        if (SelectedCreatureSlot < 0)
        {
            error = true;
        }
        else
        {
            selectedCreature = GetCreatureFromSlot(SelectedCreatureSlot);
            if (selectedCreature < 0)
            {
                error = true;
            }
        }

        if (error)
        {
            CreatureImage->setVisible(false);
            CreatureName->setVisible(false);
            CreatureDeadline->setVisible(false);
            CreatureInfo->setVisible(false);
            CreatureInfo1->setVisible(false);
            CreatureInfo2->setVisible(false);

            CreatureRenameButton->setEnabled(false);
            SummonButton->setEnabled(false);
            DismissButton->setEnabled(false);
            DismissButton->setVisible(false);
            ReleaseButton->setEnabled(false);
            SemiAutoModeButton->setEnabled(false);
            AutomaticModeButton->setEnabled(false);
            OptionsMenuButton->setEnabled(false);
        }
        else
        {
            CreatureImage->setVisible(true);
            CreatureName->setVisible(true);
            CreatureDeadline->setVisible(true);
            CreatureInfo->setVisible(true);
            CreatureInfo1->setVisible(true);
            CreatureInfo2->setVisible(true);

            CreatureRenameButton->setEnabled(true);
            ReleaseButton->setEnabled(true);
            OptionsMenuButton->setEnabled(true);
            SemiAutoModeButton->setEnabled(true);
            AutomaticModeButton->setEnabled(true);

            //Check what creature is currently summoned
            if (GameScene::getUser()->CreatureSummoned)
            {
                if (GameScene::getUser()->IntelligentCreatures[selectedCreature]->PetType == GameScene::getUser()->SummonedCreatureType)
                {

                    DismissButton->setEnabled(true);
                    DismissButton->setVisible(true);
                    ReleaseButton->setEnabled(false);
                }
                else
                {
                    SummonButton->setIndex(593);
                    SummonButton->setHoverIndex(594);
                    SummonButton->setPressedIndex(595);
                    SummonButton->setEnabled(false);
                    DismissButton->setEnabled(false);
                    DismissButton->setVisible(false);
                }
            }
            else
            {
                DismissButton->setEnabled(false);
                DismissButton->setVisible(false);
                SummonButton->setIndex(576);
                SummonButton->setHoverIndex(577);
                SummonButton->setPressedIndex(578);
                SummonButton->setEnabled(true);
            }
        }


    }

    void IntelligentCreatureDialog::RefreshMode()
    {
        int selectedCreature = BeforeAfterDraw();
        if (selectedCreature < 0)
        {
            return;
        }

        if (GameScene::getUser()->IntelligentCreatures[selectedCreature]->petMode == IntelligentCreaturePickupMode::Automatic)
        {
            AutomaticModeButton->setVisible(true);
            SemiAutoModeButton->setVisible(false);
        }
        else
        {
            AutomaticModeButton->setVisible(false);
            SemiAutoModeButton->setVisible(true);
        }
    }

    int IntelligentCreatureDialog::BeforeAfterDraw()
    {
        if (FullnessFG->getLibrary() == nullptr)
        {
            return -1;
        }

        if (SelectedCreatureSlot < 0)
        {
            CreatureImage->setIndex(0);
            CreatureImage->setAnimated(false);
            FullnessFG->setVisible(false);
            FullnessMin->setVisible(false);
            FullnessNow->setVisible(false);
            return -1;
        }
        else
        {
            int selectedCreature = GetCreatureFromSlot(SelectedCreatureSlot);
            if (selectedCreature < 0)
            {
                CreatureImage->setIndex(0);
                CreatureImage->setAnimated(false);
                FullnessFG->setVisible(false);
                FullnessMin->setVisible(false);
                FullnessNow->setVisible(false);
                return -1;
            }
            FullnessFG->setVisible(true);
            FullnessMin->setVisible(true);
            FullnessNow->setVisible(true);
            return selectedCreature;
        }
    }

    void IntelligentCreatureDialog::DrawCreatureAnimation()
    {
        int selectedCreature = BeforeAfterDraw();
        if (selectedCreature < 0)
        {
            return;
        }

        auto rules = GameScene::getUser()->IntelligentCreatures[selectedCreature]->CreatureRules;

        auto semi = rules->SemiAutoPickupEnabled ? std::string::Format("{0}x{0} {1}{2}{3}", rules->AutoPickupRange, rules->AutoPickupEnabled ? "auto/" : "", rules->SemiAutoPickupEnabled ? "semi-auto" : "", rules->MousePickupEnabled ? ", " : "") : "";
        auto mouse = rules->SemiAutoPickupEnabled ? StringHelper::formatSimple("{0}x{0} mouse", rules->MousePickupRange) : "";

        CreatureName->setText(GameScene::getUser()->IntelligentCreatures[selectedCreature]->CustomName);
        CreatureInfo->setText(StringHelper::formatSimple("Can pickup items ({0}{1}).", semi, mouse));
        CreatureInfo1->setText(rules->CanProduceBlackStone ? "Can produce BlackStones." : "");
        CreatureInfo2->setText(rules->CanProduceBlackStone ? "Can produce Pearls, used to buy Creature items." : "");

        //Expire
        if (GameScene::getUser()->IntelligentCreatures[selectedCreature]->Expire == DateTime::MinValue)
        {
            CreatureDeadline->setText(std::string::Format(GameLanguage::ExpireNever));
        }
        else
        {
            auto seconds = (GameScene::getUser()->IntelligentCreatures[selectedCreature]->Expire - DateTime::Now).TotalSeconds;

            CreatureDeadline->setText(std::string::Format(GameLanguage::Expire, Functions::PrintTimeSpanFromSeconds(seconds)));
        }

        if (GameScene::getUser()->IntelligentCreatures[selectedCreature]->MaintainFoodTime == 0)
        {
            CreatureMaintainFoodBuff->setText("0");
        }
        else
        {
            CreatureMaintainFoodBuff->setText(StringHelper::formatSimple("FoodBuff: {0}", Functions::PrintTimeSpanFromSeconds(GameScene::getUser()->IntelligentCreatures[selectedCreature]->MaintainFoodTime)));
        }

        int StartIndex = CreatureButtons[SelectedCreatureSlot]->AnimDefaultIdx;
        int AnimCount = CreatureButtons[SelectedCreatureSlot]->AnimDefaultCount;
        long long AnimDelay = CreatureButtons[SelectedCreatureSlot]->AnimDefaultDelay;

        if (AnimSwitched)
        {
            StartIndex = CreatureButtons[SelectedCreatureSlot]->AnimExIdx;
            AnimCount = CreatureButtons[SelectedCreatureSlot]->AnimExCount;
            AnimDelay = CreatureButtons[SelectedCreatureSlot]->AnimExDelay;
        }

        if (SwitchAnimTime <= CMain::Time) //need switch
        {
            if (!AnimSwitched)
            {
                AnimNeedSwitch = true;
            }
        }

        bool AnimExFinished = false;
        if ((CreatureImage->getIndex() - StartIndex) >= AnimCount - 1)
        {
            AnimExFinished = true;
        }

        CreatureImage->setAnimationCount(AnimCount);
        CreatureImage->setAnimationDelay(AnimDelay);
        CreatureImage->setIndex(StartIndex); //sets base.Index
        if (!CreatureImage->getAnimated())
        {
            CreatureImage->setAnimated(true);
        }

        if (AnimExFinished)
        {
            if (AnimNeedSwitch)
            {
                SwitchAnimTime = CMain::Time + 8000;
                AnimSwitched = true;
            }
            else if (AnimSwitched)
            {
                SwitchAnimTime = CMain::Time + 8000;
                AnimSwitched = false;
            }
            CreatureImage->setOffSet(0);
            AnimNeedSwitch = false;
        }
    }

    int IntelligentCreatureDialog::GetCreatureFromSlot(int slotidx)
    {
        for (int i = 0; i < GameScene::getUser()->IntelligentCreatures.size(); i++)
        {
            if (GameScene::getUser()->IntelligentCreatures[i]->SlotIndex == slotidx)
            {
                return i;
            }
        }
        return -1;
    }

    void IntelligentCreatureDialog::SaveItemFilter(IntelligentCreatureItemFilter *filter)
    {
        int selectedCreature = BeforeAfterDraw();
        if (selectedCreature < 0)
        {
            return;
        }

        GameScene::getUser()->IntelligentCreatures[selectedCreature]->Filter = filter;
        C::UpdateIntelligentCreature *tempVar = new C::UpdateIntelligentCreature();
        tempVar->Creature = GameScene::getUser()->IntelligentCreatures[selectedCreature];
        Network::Enqueue(tempVar);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
    }

    void IntelligentCreatureDialog::OnMouseDown(MouseEventArgs *e)
    {
        MirImageControl::OnMouseDown(e);
        if (GameScene::Scene->IntelligentCreatureOptionsGradeDialog->getVisible())
        {
            GameScene::Scene->IntelligentCreatureOptionsGradeDialog->BringToFront();
        }
        if (GameScene::Scene->IntelligentCreatureOptionsDialog->getVisible())
        {
            GameScene::Scene->IntelligentCreatureOptionsDialog->BringToFront();
        }
    }

    void IntelligentCreatureDialog::Hide()
    {
        if (!getVisible())
        {
            return;
        }
        if (GameScene::Scene->IntelligentCreatureOptionsGradeDialog->getVisible())
        {
            GameScene::Scene->IntelligentCreatureOptionsGradeDialog->Hide();
        }
        if (GameScene::Scene->IntelligentCreatureOptionsDialog->getVisible())
        {
            GameScene::Scene->IntelligentCreatureOptionsDialog->Hide();
        }
        AnimSwitched = false;
        AnimNeedSwitch = false;
        setVisible(false);

        C::RequestIntelligentCreatureUpdates *tempVar = new C::RequestIntelligentCreatureUpdates();
        tempVar->Update = false;
        Network::Enqueue(tempVar);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
    }

    void IntelligentCreatureDialog::Show()
    {
        if (getVisible())
        {
            return;
        }

        if (!GameScene::getUser()->IntelligentCreatures.Any())
        {
            MirMessageBox *messageBox = new MirMessageBox(GameLanguage::NoCreatures, MirMessageBoxButtons::OK);
            messageBox->Show();

            delete messageBox;
            return;
        }

        if (!CreatureButtons.Any([&] (std::any x)
        {
            x::Selected;
        }))
        {
            CreatureButtons[0]->SelectButton();
        }

        C::RequestIntelligentCreatureUpdates *tempVar = new C::RequestIntelligentCreatureUpdates();
        tempVar->Update = true;
        Network::Enqueue(tempVar);

        setVisible(true);
        showing = true;
        SwitchAnimTime = CMain::Time + 8000;
        AnimSwitched = false;
        AnimNeedSwitch = false;
        RefreshDialog();

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
    }

    CreatureButton::CreatureButton()
    {
        Size tempVar(231, 33);
        setSize(&tempVar);

        PetButton = new MirButton();
        PetButton->setIndex(0);
        PetButton->setPressedIndex(1);
        PetButton->setLibrary(Libraries::Prguse2);
        PetButton->setParent(this);
        Point tempVar2(0, 0);
        PetButton->setLocation(&tempVar2);
        PetButton->setSound(SoundList::ButtonA);
        PetButton->Click += PetButtonClick;
        PetButton->MouseEnter += PetButtonMouseEnter;
        PetButton->MouseLeave += PetButtonMouseLeave;

        SelectionImage = new MirImageControl();
        SelectionImage->setIndex(535);
        SelectionImage->setLibrary(Libraries::Prguse2);
        Point tempVar3(-2, -2);
        SelectionImage->setLocation(&tempVar3);
        SelectionImage->setParent(this);
        SelectionImage->setNotControl(true);
        SelectionImage->setVisible(false);

        NameLabel = new MirLabel();
        NameLabel->setParent(this);
        Point tempVar4(-22, -12);
        NameLabel->setLocation(&tempVar4);
        NameLabel->setDrawFormat(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter);
        Size tempVar5(80, 15);
        NameLabel->setSize(&tempVar5);
        NameLabel->setNotControl(true);
        NameLabel->setVisible(false);

    }

    void CreatureButton::SetButtonInfo(ClientIntelligentCreature *pet)
    {
        if (pet == nullptr)
        {
            return;
        }

        PetType = pet->PetType;

//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
        NameLabel->setText(pet->CustomName.ToString());

        PetButton->setIndex(pet->Icon);
        PetButton->setPressedIndex(pet->Icon);

        SetCreatureFrames();
    }

    void CreatureButton::Update(ClientIntelligentCreature *pet, bool setnew)
    {
        if (pet == nullptr)
        {
            return;
        }
        if (PetType == IntelligentCreatureType::None || PetType != pet->PetType)
        {
            setnew = true; //force new
        }

        if (setnew)
        {
            SetButtonInfo(pet);
        }
        else
        {
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
            NameLabel->setText(pet->CustomName.ToString());
        }
    }

    void CreatureButton::PetButtonClick(std::any sender, EventArgs *e)
    {
        SelectButton();
    }

    void CreatureButton::PetButtonMouseEnter(std::any sender, EventArgs *e)
    {
        NameLabel->setVisible(true);
    }

    void CreatureButton::PetButtonMouseLeave(std::any sender, EventArgs *e)
    {
        NameLabel->setVisible(false);
    }

    void CreatureButton::SelectButton()
    {
        if (Selected)
        {
            return;
        }
        for (int i = 0; i < GameScene::Scene->IntelligentCreatureDialog->CreatureButtons.size(); i++)
        {
            if (i == idx)
            {
                continue;
            }
            GameScene::Scene->IntelligentCreatureDialog->CreatureButtons[i]->SelectButton(false);
        }

        SelectButton(true);
        GameScene::Scene->IntelligentCreatureDialog->SelectedCreatureSlot = idx;
        GameScene::Scene->IntelligentCreatureDialog->SwitchAnimTime = CMain::Time + 10000;
        GameScene::Scene->IntelligentCreatureDialog->AnimSwitched = false;
        GameScene::Scene->IntelligentCreatureDialog->AnimNeedSwitch = false;
        GameScene::Scene->IntelligentCreatureDialog->Update();
    }

    void CreatureButton::SelectButton(bool selection)
    {
        Selected = selection;
        SelectionImage->setVisible(Selected);
    }

    void CreatureButton::Clear()
    {
        PetType = IntelligentCreatureType::None;
        setVisible(false);
        SelectButton(false);
    }

    void CreatureButton::SetCreatureFrames()
    {
        switch (PetType)
        {
            case IntelligentCreatureType::BabyPig:
                AnimDefaultIdx = 540;
                AnimDefaultCount = 6;
                AnimDefaultDelay = 200;

                AnimExIdx = 550;
                AnimExCount = 5;
                AnimExDelay = 300;
                break;
            case IntelligentCreatureType::Chick:
                AnimDefaultIdx = 570;
                AnimDefaultCount = 4;
                AnimDefaultDelay = 350;

                AnimExIdx = 580;
                AnimExCount = 10;
                AnimExDelay = 200;
                break;
            case IntelligentCreatureType::Kitten:
                AnimDefaultIdx = 600;
                AnimDefaultCount = 6;
                AnimDefaultDelay = 250;

                AnimExIdx = 610;
                AnimExCount = 10;
                AnimExDelay = 200;
                break;
            case IntelligentCreatureType::BabySkeleton:
                AnimDefaultIdx = 630;
                AnimDefaultCount = 11;
                AnimDefaultDelay = 200;

                AnimExIdx = 650;
                AnimExCount = 7;
                AnimExDelay = 250;
                break;
            case IntelligentCreatureType::Baekdon:
                AnimDefaultIdx = 660;
                AnimDefaultCount = 6;
                AnimDefaultDelay = 250;

                AnimExIdx = 670;
                AnimExCount = 8;
                AnimExDelay = 250;
                break;
            case IntelligentCreatureType::Wimaen:
                AnimDefaultIdx = 690;
                AnimDefaultCount = 4;
                AnimDefaultDelay = 350;

                AnimExIdx = 700;
                AnimExCount = 6;
                AnimExDelay = 300;
                break;
            case IntelligentCreatureType::BlackKitten:
                AnimDefaultIdx = 720;
                AnimDefaultCount = 6;
                AnimDefaultDelay = 250;

                AnimExIdx = 730;
                AnimExCount = 10;
                AnimExDelay = 200;
                break;
            case IntelligentCreatureType::BabyDragon:
                AnimDefaultIdx = 750;
                AnimDefaultCount = 6;
                AnimDefaultDelay = 300;

                AnimExIdx = 760;
                AnimExCount = 7;
                AnimExDelay = 250;
                break;
            case IntelligentCreatureType::OlympicFlame:
                AnimDefaultIdx = 780;
                AnimDefaultCount = 6;
                AnimDefaultDelay = 300;

                AnimExIdx = 790;
                AnimExCount = 10;
                AnimExDelay = 200;
                break;
            case IntelligentCreatureType::BabySnowMan:
                AnimDefaultIdx = 810;
                AnimDefaultCount = 6;
                AnimDefaultDelay = 300;

                AnimExIdx = 820;
                AnimExCount = 6;
                AnimExDelay = 300;
                break;
            case IntelligentCreatureType::Frog:
                AnimDefaultIdx = 840;
                AnimDefaultCount = 6;
                AnimDefaultDelay = 300;
                AnimExIdx = 850;
                AnimExCount = 6;
                AnimExDelay = 300;
                break;
            case IntelligentCreatureType::BabyMonkey:
                AnimDefaultIdx = 870;
                AnimDefaultCount = 6;
                AnimDefaultDelay = 300;
                AnimExIdx = 880;
                AnimExCount = 9;
                AnimExDelay = 300;
                break;
            case IntelligentCreatureType::AngryBird:
                AnimDefaultIdx = 1400;
                AnimDefaultCount = 12;
                AnimDefaultDelay = 300;
                AnimExIdx = 1332;
                AnimExCount = 12;
                AnimExDelay = 300;
                break;
            case IntelligentCreatureType::Foxey:
                AnimDefaultIdx = 1430;
                AnimDefaultCount = 9;
                AnimDefaultDelay = 300;
                AnimExIdx = 1439;
                AnimExCount = 8;
                AnimExDelay = 300;
                break;
            case IntelligentCreatureType::MedicalRat:
                AnimDefaultIdx = 1550;
                AnimDefaultCount = 8;
                AnimDefaultDelay = 300;
                AnimExIdx = 1560;
                AnimExCount = 16;
                AnimExDelay = 300;
                break;
            case IntelligentCreatureType::None:
                AnimDefaultIdx = 539;
                AnimDefaultCount = 1;
                AnimDefaultDelay = 000;
                AnimExIdx = 539;
                AnimExCount = 1;
                AnimExDelay = 000;
                break;
        }
    }

    IntelligentCreatureOptionsDialog::IntelligentCreatureOptionsDialog()
    {
        setIndex(469);
        setLibrary(Libraries::Title);
        setMovable(false);
        setSort(true);
        Point tempVar(GameScene::Scene->IntelligentCreatureDialog->getLocation()->X + locationOffset->X, GameScene::Scene->IntelligentCreatureDialog->getLocation()->Y + locationOffset->Y);
        setLocation(&tempVar);
        BeforeDraw += IntelligentCreatureOptionsDialog_BeforeDraw;

        CreatureOptions = std::vector<MirCheckBox*>(9);
        for (int i = 0; i < CreatureOptions.size(); i++)
        {
            int offsetY = i * 30;
            MirCheckBox *tempVar2 = new MirCheckBox();
            tempVar2->setIndex(2086);
            tempVar2->setUnTickedIndex(2086);
            tempVar2->setTickedIndex(2087);
            tempVar2->setParent(this);
            Point tempVar3(16, (16 + offsetY));
            tempVar2->setLocation(&tempVar3);
            tempVar2->setLibrary(Libraries::Prguse);
            CreatureOptions[i] = tempVar2;
            CreatureOptions[i]->setLabelText(OptionNames[i]);
            CreatureOptions[i]->Click += CheckBoxClick;

            delete tempVar2;
        }

        OptionsSaveButton = new MirButton();
        OptionsSaveButton->setHoverIndex(587);
        OptionsSaveButton->setIndex(586);
        Point tempVar4(10, 280);
        OptionsSaveButton->setLocation(&tempVar4);
        OptionsSaveButton->setLibrary(Libraries::Title);
        OptionsSaveButton->setParent(this);
        OptionsSaveButton->setPressedIndex(588);
        OptionsSaveButton->setSound(SoundList::ButtonA);
        OptionsSaveButton->Click += ButtonClick;

        OptionsCancelButton = new MirButton();
        OptionsCancelButton->setHoverIndex(591);
        OptionsCancelButton->setIndex(590);
        Point tempVar5(60, 280);
        OptionsCancelButton->setLocation(&tempVar5);
        OptionsCancelButton->setLibrary(Libraries::Title);
        OptionsCancelButton->setParent(this);
        OptionsCancelButton->setPressedIndex(592);
        OptionsCancelButton->setSound(SoundList::ButtonA);
        OptionsCancelButton->Click += ButtonClick;
    }

    void IntelligentCreatureOptionsDialog::ButtonClick(std::any sender, EventArgs *e)
    {
        if (obj::type() == typeid(Client::MirControls::MirButton) && std::any_cast<Client::MirControls::MirButton>(obj) == OptionsSaveButton)
        {
            Filter->PickupGrade = GameScene::Scene->IntelligentCreatureOptionsGradeDialog->GradeType;
            GameScene::Scene->IntelligentCreatureOptionsGradeDialog->Hide();
            GameScene::Scene->IntelligentCreatureDialog->SaveItemFilter(Filter);
            Hide();
        }
        if (obj::type() == typeid(Client::MirControls::MirButton) && std::any_cast<Client::MirControls::MirButton>(obj) == OptionsCancelButton)
        {
            Filter = new IntelligentCreatureItemFilter();
            GameScene::Scene->IntelligentCreatureOptionsGradeDialog->GradeType = ItemGrade::None;
            GameScene::Scene->IntelligentCreatureOptionsGradeDialog->RefreshGradeFilter();
            GameScene::Scene->IntelligentCreatureOptionsGradeDialog->Hide();
            RefreshFilter();
            Hide();
        }
    }

    void IntelligentCreatureOptionsDialog::CheckBoxClick(std::any sender, EventArgs *e)
    {
        for (int i = 0; i < CreatureOptions.size(); i++)
        {
            if (CreatureOptions[i] != sender)
            {
                continue;
            }
            Filter->SetItemFilter(i);
            break;
        }
        RefreshFilter();
    }

    void IntelligentCreatureOptionsDialog::IntelligentCreatureOptionsDialog_BeforeDraw(std::any sender, EventArgs *e)
    {
        if (!GameScene::Scene->IntelligentCreatureDialog->getVisible())
        {
            Hide();
            return;
        }
        Point tempVar(GameScene::Scene->IntelligentCreatureDialog->getLocation()->X + locationOffset->X, GameScene::Scene->IntelligentCreatureDialog->getLocation()->Y + locationOffset->Y);
        setLocation(&tempVar);
    }

    void IntelligentCreatureOptionsDialog::RefreshFilter()
    {
        for (int i = 0; i < CreatureOptions.size(); i++)
        {
            switch (i)
            {
                case 0: //all items
                    CreatureOptions[i]->setChecked(Filter->PetPickupAll);
                    break;
                case 1: //gold
                    CreatureOptions[i]->setChecked(Filter->PetPickupGold);
                    break;
                case 2: //weapons
                    CreatureOptions[i]->setChecked(Filter->PetPickupWeapons);
                    break;
                case 3: //armours
                    CreatureOptions[i]->setChecked(Filter->PetPickupArmours);
                    break;
                case 4: //helmets
                    CreatureOptions[i]->setChecked(Filter->PetPickupHelmets);
                    break;
                case 5: //boots
                    CreatureOptions[i]->setChecked(Filter->PetPickupBoots);
                    break;
                case 6: //belts
                    CreatureOptions[i]->setChecked(Filter->PetPickupBelts);
                    break;
                case 7: //jewelry
                    CreatureOptions[i]->setChecked(Filter->PetPickupAccessories);
                    break;
                case 8: //others
                    CreatureOptions[i]->setChecked(Filter->PetPickupOthers);
                    break;
            }
        }
    }

    void IntelligentCreatureOptionsDialog::Show(IntelligentCreatureItemFilter *filter)
    {
        if (getVisible())
        {
            return;
        }
        Filter = filter;
        setVisible(true);
        RefreshFilter();
    }

    IntelligentCreatureOptionsGradeDialog::IntelligentCreatureOptionsGradeDialog()
    {
        setIndex(237);
        setLibrary(Libraries::Prguse);
        setMovable(false);
        setSort(true);
        Point tempVar(GameScene::Scene->IntelligentCreatureDialog->getLocation()->X + locationOffset->X, GameScene::Scene->IntelligentCreatureDialog->getLocation()->Y + locationOffset->Y);
        setLocation(&tempVar);
        BeforeDraw += IntelligentCreatureOptionsGradeDialog_BeforeDraw;

        NextButton = new MirButton();
        NextButton->setHoverIndex(396);
        NextButton->setIndex(396);
        Point tempVar2(96, 5);
        NextButton->setLocation(&tempVar2);
        NextButton->setLibrary(Libraries::Prguse);
        NextButton->setParent(this);
        NextButton->setPressedIndex(397);
        NextButton->setSound(SoundList::ButtonA);
        NextButton->Click += Button_Click;

        PrevButton = new MirButton();
        PrevButton->setHoverIndex(398);
        PrevButton->setIndex(398);
        Point tempVar3(76, 5);
        PrevButton->setLocation(&tempVar3);
        PrevButton->setLibrary(Libraries::Prguse);
        PrevButton->setParent(this);
        PrevButton->setPressedIndex(399);
        PrevButton->setSound(SoundList::ButtonA);
        PrevButton->Click += Button_Click;

        GradeLabel = new MirLabel();
        GradeLabel->setParent(this);
        Point tempVar4(8, 0);
        GradeLabel->setLocation(&tempVar4);
        GradeLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        Size tempVar5(70, 21);
        GradeLabel->setSize(&tempVar5);
        GradeLabel->setNotControl(true);
    }

    void IntelligentCreatureOptionsGradeDialog::Button_Click(std::any sender, EventArgs *e)
    {
        if (obj::type() == typeid(Client::MirControls::MirButton) && std::any_cast<Client::MirControls::MirButton>(obj) == NextButton)
        {
            SelectedGrade++;
            if (SelectedGrade >= GradeStrings.size())
            {
                SelectedGrade = GradeStrings.size() - 1;
            }
        }
        if (obj::type() == typeid(Client::MirControls::MirButton) && std::any_cast<Client::MirControls::MirButton>(obj) == PrevButton)
        {
            SelectedGrade--;
            if (SelectedGrade <= 0)
            {
                SelectedGrade = 0;
            }
        }

        GradeLabel->setText(GradeStrings[SelectedGrade]);
        GradeType = static_cast<ItemGrade>(static_cast<unsigned char>(SelectedGrade));

        GradeLabel->setForeColour(GradeNameColor(GradeType));
    }

    Color *IntelligentCreatureOptionsGradeDialog::GradeNameColor(ItemGrade grade)
    {
        switch (grade)
        {
            case ItemGrade::Common:
                return Color::Yellow;
            case ItemGrade::Rare:
                return Color::DeepSkyBlue;
            case ItemGrade::Legendary:
                return Color::DarkOrange;
            case ItemGrade::Mythical:
                return Color::Plum;
            default:
                return Color::White;
        }
    }

    void IntelligentCreatureOptionsGradeDialog::IntelligentCreatureOptionsGradeDialog_BeforeDraw(std::any sender, EventArgs *e)
    {
        if (!GameScene::Scene->IntelligentCreatureDialog->getVisible())
        {
            Hide();
            return;
        }
        Point tempVar(GameScene::Scene->IntelligentCreatureDialog->getLocation()->X + locationOffset->X, GameScene::Scene->IntelligentCreatureDialog->getLocation()->Y + locationOffset->Y);
        setLocation(&tempVar);
    }

    void IntelligentCreatureOptionsGradeDialog::RefreshGradeFilter()
    {
        SelectedGrade = static_cast<int>(static_cast<unsigned char>(GradeType));
        GradeLabel->setText(GradeStrings[SelectedGrade]);
        GradeLabel->setForeColour(GradeNameColor(GradeType));
    }

    void IntelligentCreatureOptionsGradeDialog::Show(ItemGrade grade)
    {
        if (getVisible())
        {
            return;
        }
        setVisible(true);
        GradeType = grade;
        RefreshGradeFilter();
    }
}
